/*********************************************************
          File Name:8.1.cpp
          Author: Abby Cin
          Mail: abbytsing@gmail.com
          Created Time: Mon 14 Sep 2015 10:06:40 AM CST
**********************************************************/

#include <iostream>
using namespace std;

istream &fun(istream &is)
{
        std::string buf;
        while(is >> buf)
                cout << buf << endl;
        auto stat = is.rdstate();
        cout << "before clear() " << stat << endl;   // `<C-D>` stat = 6
        is.clear();
        return is;
}

int main()
{

        cout << unitbuf;                // no buffer

        istream &is = fun(cin);

        cout << "after clear() " << is.rdstate() << endl;

        cout << nounitbuf;              // with buffer
        cout.tie(&cerr);
        cout << "hehe" << endl;

        cin.tie(&cout);         // bind cin to cout;
        string s;
        cin >> s;
        cout << s << "\n";      
        cin.tie(nullptr);       // break bind between cin and cout;
}
